<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<title>滴答办公系统-部门列表</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="media/layui/css/layui.css" media="all">
<script src="media/js/jquery.min.js"></script>
	<script type="text/javascript">
		function junpage(pageCount,pageSize) {
			var pagenum = $("#pagejun").val();
			var regex = /^[1-9]\d*$/;
			if (regex.test(pagenum)){
				if(pagenum>=1 && pagenum<=pageCount){
					location.href="/depart_list?pageIndex="+pagenum+"&pageSize=" + pageSize;
				}else {
					alert("请输入一个合法的数字")
				}
			}else {
				alert("请输入一个数学")
			}
		}
		function changePageSize(pageSize) {
			location.href="/depart_list?pageIndex=1&pageSize=" + pageSize;
		}
	</script>
</head>
<body>
	<div class="layui-container">
		<table class="layui-table" id="tbdata" lay-filter="tbop">
			<thead>
				<tr>
					<td>序号</td>
					<td>部门名称</td>
					<td>部门人数</td>
					<td>成立日期</td>
					<td>操作</td>
				</tr>
			</thead>
			<tbody id="tt">
				<tr th:id="|tr_${d.id}|" th:each="d:${pageUtils.records}">
					<td th:text="${d.id}">序号</td>
					<td th:text="${d.name}">部门名称</td>
					<td th:text="${d.empCount}">0</td>
					<td th:text="${d.createtime}">成立日期</td>
					<td>

						<a class="layui-btn layui-btn-mini" th:href="|depart_update/${d.id}|">编辑</a>
						<a class="layui-btn layui-btn-danger layui-btn-mini"
						   lay-event="del" th:onclick="|deleteCourse(${d.id});|">删除</a></td>
				</tr >
			</tbody>
		</table>
		<div class="layui-box layui-laypage layui-laypage-default" id="layui-laypage-1">
						   <a th:href="|/depart_list?pageIndex=${pageUtils.pageIndex-1}&pageSize=${pageUtils.pageSize}|"
							  th:if="${pageUtils.pageIndex>1}" class="layui-laypage-prev " data-page="0">
							    <i class="layui-icon">&lt;</i>
						   </a> 
<!--							    <span style="color:#009688;font-weight: bold;">1</span>-->

							    <a th:each="num:${pageUtils.numbers}" th:style="${pageUtils.pageIndex==num} ? 'color:#009688;font-weight: bold;':''" th:href="|/depart_list?pageIndex=${num}&pageSize=${pageUtils.pageSize}|"  th:text="${num}"></a>
							<a th:href="|/depart_list?pageIndex=${pageUtils.pageIndex+1}&pageSize=${pageUtils.pageSize}|"
							   th:if="${pageUtils.pageIndex<pageUtils.pageCount}" class="layui-laypage-next" data-page="2">
								<i class="layui-icon">&gt;</i>
							</a> 
							<span class="layui-laypage-skip">到第
							   <input type="text" min="1" id="pagejun" th:value="${pageUtils.pageIndex}" class="layui-input">页
								<button type="button" class="layui-laypage-btn"
								th:onclick="|junpage(${pageUtils.pageCount},${pageUtils.pageSize})|">确定</button>
							</span> 
							<span class="layui-laypage-count">当前[[${pageUtils.pageIndex}]]/[[${pageUtils.pageCount}]]页/[[${pageUtils.totalCount}]]条</span>
							<span class="layui-laypage-limits"> 
							    <select lay-ignore="" onchange="changePageSize(this.value)">
							        <option value="5" th:selected="${pageUtils.pageSize==5}">5 条/页</option>
									<option value="10" th:selected="${pageUtils.pageSize==10}">10 条/页</option>
									<option value="15" th:selected="${pageUtils.pageSize==15}">15 条/页</option>
							</select>
							</span>
						</div>
	</div>
	<script src="media/layui/layui.js"></script>
	
	<script type="text/javascript">
	   function deleteCourse(id){

		   layui.use('table', function() {
			   layer.confirm('是否确认删除部门?',function(index) {
					$.getJSON("/delete_dep","id="+id,function (result) {
						// alert(result);
						if (result==true){
							layer.msg("删除成功", {icon : 6});
							$("#tr_"+id).fadeOut(2000,function () {
								window.location.reload();

							})
						}else {
							layer.msg("删除失败", {icon : 5});
						}
					})

			   });
		   });
	   }


	</script>
	
	
</body>
</html>